package com.fenqing.leetcode.code.t2100_2200;

import com.fenqing.annotations.Execute;
import com.fenqing.bean.ListNode;
import com.fenqing.core.Topic;

public class Topic2181 extends Topic {

    @Execute
    public ListNode mergeNodes(ListNode head) {
        ListNode curr = head;
        ListNode result = new ListNode();
        ListNode now = result;
        while (curr != null) {
            if (curr.val == 0) {
                int sum = 0;
                ListNode temp = curr.next;
                while (temp != null && temp.val != 0) {
                    sum += temp.val;
                    temp = temp.next;
                }
                curr = temp;
                if (sum != 0) {
                    now.next = new ListNode(sum);
                    now = now.next;
                }
            }
        }
        return result.next;
    }

    public static void main(String[] args) {
        ListNode result = new Topic2181().run("[0,3,1,0,4,5,2,0]");
        System.out.println();
    }

}
